// app.js
App({
  onLaunch: function () {
    // 初始化本地数据
    this.initLocalStorage();
    
    // 获取用户信息
    wx.getUserInfo({
      success: res => {
        this.globalData.userInfo = res.userInfo;
      }
    });
  },
  
  // 初始化本地存储
  initLocalStorage: function () {
    const weightRecords = wx.getStorageSync('weightRecords') || [];
    const healthPlans = wx.getStorageSync('healthPlans') || this.getDefaultHealthPlans();
    
    if (!weightRecords.length) {
      wx.setStorageSync('weightRecords', []);
    }
    
    if (!healthPlans.length) {
      wx.setStorageSync('healthPlans', this.getDefaultHealthPlans());
    }
  },
  
  // 获取默认健康计划
  getDefaultHealthPlans: function () {
    return [
      { id: 1, name: '每日喝水2000ml', completed: false, target: 2000, unit: 'ml' },
      { id: 2, name: '每日步行10000步', completed: false, target: 10000, unit: '步' },
      { id: 3, name: '控制饮食热量', completed: false, target: 0, unit: '千卡' }
    ];
  },
  
  // 全局数据
  globalData: {
    userInfo: null
  }
}) 